import { Model } from 'sequelize';

export * from './init';

export class MySqlModel extends Model {
  /**
   * 通过id获取实例
   * @param {string} id 实例id
   * @returns
   */
  static async findById(id) {
    return this.findOne({ where: { id } });
  }

  static async getAttributeValue(id, attribute) {
    const data = await this.findOne({ where: { id }, rejectOnEmpty: new Error('数据不存在') });
    return {
      value: attribute ? data.getDataValue(attribute) : attribute,
      instance: data
    };
  }
}
